package com.charging.system.service.impl;

import java.util.List;

import com.charging.common.constant.Constants;
import com.charging.common.utils.DateUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.charging.system.mapper.KxSystemInfoMapper;
import com.charging.system.domain.KxSystemInfo;
import com.charging.system.service.IKxSystemInfoService;

import javax.annotation.Resource;

/**
 * 平台设置Service业务层处理
 *
 * @author charging
 * @date 2024-04-20
 */
@Service
public class KxSystemInfoServiceImpl implements IKxSystemInfoService
{
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    private KxSystemInfoMapper kxSystemInfoMapper;

    /**
     * 查询平台设置
     *
     * @param systemInfoId 平台设置主键
     * @return 平台设置
     */
    @Override
    public KxSystemInfo selectKxSystemInfoBySystemInfoId(Long systemInfoId)
    {
        return kxSystemInfoMapper.selectKxSystemInfoBySystemInfoId(systemInfoId);
    }

    /**
     * 查询平台设置列表
     *
     * @param kxSystemInfo 平台设置
     * @return 平台设置
     */
    @Override
    public List<KxSystemInfo> selectKxSystemInfoList(KxSystemInfo kxSystemInfo)
    {
        return kxSystemInfoMapper.selectKxSystemInfoList(kxSystemInfo);
    }

    /**
     * 新增平台设置
     *
     * @param kxSystemInfo 平台设置
     * @return 结果
     */
    @Override
    public int insertKxSystemInfo(KxSystemInfo kxSystemInfo)
    {
        kxSystemInfo.setCreateTime(DateUtils.getNowDate());
        return kxSystemInfoMapper.insertKxSystemInfo(kxSystemInfo);
    }

    /**
     * 修改平台设置
     *
     * @param kxSystemInfo 平台设置
     * @return 结果
     */
    @Override
    public int updateKxSystemInfo(KxSystemInfo kxSystemInfo)
    {
        Constants.kxSystemInfo = null;
        kxSystemInfo.setUpdateTime(DateUtils.getNowDate());
        int up = kxSystemInfoMapper.updateKxSystemInfo(kxSystemInfo);
        Constants.kxSystemInfo = kxSystemInfoMapper.selectKxSystemInfoBySystemInfoId(1L);
        return up;
    }

    /**
     * 批量删除平台设置
     *
     * @param systemInfoIds 需要删除的平台设置主键
     * @return 结果
     */
    @Override
    public int deleteKxSystemInfoBySystemInfoIds(Long[] systemInfoIds)
    {
        return kxSystemInfoMapper.deleteKxSystemInfoBySystemInfoIds(systemInfoIds);
    }

    /**
     * 删除平台设置信息
     *
     * @param systemInfoId 平台设置主键
     * @return 结果
     */
    @Override
    public int deleteKxSystemInfoBySystemInfoId(Long systemInfoId)
    {
        return kxSystemInfoMapper.deleteKxSystemInfoBySystemInfoId(systemInfoId);
    }

    /**
     * 获取系统信息
     * @return
     */
    @Override
    public KxSystemInfo getKxSystemInfo() {
        if (ObjectUtils.isEmpty(Constants.kxSystemInfo.getSystemInfoId())) {
            logger.info("===获取系统基础信息===");
            Constants.kxSystemInfo = kxSystemInfoMapper.selectKxSystemInfoBySystemInfoId(1L);
        }
        return Constants.kxSystemInfo;
    }
}
